/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */

 function judge(n1,n2){
    if(n1==null&&n2==null){
        return true;
    }
    if(n1&&n2){
        if(n1==n2||n1.val==n2.val){
            if(n1){
                return judge(n1.left,n2.right)&&judge(n1.right,n2.left);
            }
            return true;
        }
        return false;
    }
    return false
}

var isSymmetric = function(root) {
    return judge(root.left,root.right);
};